package wickethub.web.components;

import org.apache.wicket.RequestCycle;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.model.IModel;

import wickethub.domain.BlogPost;
import wickethub.domain.Resource;
import wickethub.domain.Snippet;

public class ResourceIconImage extends Image {
	
	private final String type;
	private final String root = RequestCycle.get().getRequest().getRelativePathPrefixToContextRoot();
	
	public ResourceIconImage(String id, IModel<Resource> model) {
		super(id);
		
		if (Snippet.class.isAssignableFrom(model.getObject().getClass())) {
			type = "cs";
		} else if (BlogPost.class.isAssignableFrom(model.getObject().getClass())) {
			type = "bp";
		} else { // for other resource, default Component
			type = "co";
		}
		
	}
	
	@Override
	protected void onComponentTag(ComponentTag tag) {
		checkComponentTag(tag, "img");
        tag.put("src", root + "img/icon-" + type + ".png");
	}

}
